<template>
  <div>
    promise学练
    <button @click="promsie1">promise1 test</button>
  </div>
</template>
<script>
export default {
  name: 'MyPromise',
  data() {
    return {

    }
  },
  created() {
    // this.promsie1();
  },
  methods: {
    promsie1() {
      console.log('click promise1')
      const p = new Promise((resolve, reject) => {
        setTimeout(() => {
          // resolve('ok');
          reject('oho');
          // const timer = Date.now();
          // if (timer % 2 == 1) {
          //   resolve('ok, ' + timer)
          // }else{
          //   reject('oho, ' + timer)
          // }
        }, 1000) 
      })
      p.then(
        (val) => {
          console.log('获取到异步得到的值-成功', val)
          return '来自一层链式的结果'
        },
        (err) => {
          console.log('获取到异步得到的值-失败', err)
          throw new Error(err)
        }
      ).then(
        (val) => {
          console.log('获取到异步得到的值-成功', val)
        },
        (err) => {
          console.log('获取到异步得到的值-失败', err)
        }
      )
    }
  }
}
</script>
<style>
</style>